﻿using System;
using System.Collections.Generic;
using System.Text;
using Paulovich.Data;
using Paulovich.Data.SqlBuilder;
using System.Data;

namespace DJJuninho.Business
{
    [Table("News")]
	public class News: Persist  {

		#region fields & properties

		[PrimaryKeyField(IsIdentity=true)]
        public int NewsId { get; set; }

		[Field]
        public int CategorySectionId { get; set; }

		[Field]
        public string Name { get; set; }

		[Field]
        public string Description { get; set; }

		[Field]
        public string HtmlBody { get; set; }

		[Field]
        public string Photo { get; set; }

		[Field]
        public string MiniPhoto { get; set; }

		[Field]
        public DateTime CreatedDate { get; set; }

		[Field]
        public int? AlbumId { get; set; }

		#endregion

		#region constructors

		public News()
			: base() {
		}

		public News(params object[] keys)
			: base(keys) {
		}

        #endregion


        public static DataTable SelectOrderingByName()
        {

            try
            {

                var query = new SelectBuilder();

                query.Select.Add("NewsId, Name");
                query.TableName = "News";
                query.OrderBy = "Name";

                var command = new Command();

                command.CommandText = query.ToString();

                return (DataTable)command.ExecuteQuery(ReturnType.DataTable);

            }
            catch (Exception)
            {

                throw;
            }

        }
    }

}
